package kosta.model.reply;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class ReplyDaoImpl implements ReplyDao{
	@Resource(name="sqlSessionTemplate")
	private SqlSessionTemplate sqlSessionTemplate;
	
	@Override
	// 댓글 등록 
	public void insertReply(ReplyVO rvo) throws SQLException {
		sqlSessionTemplate.insert("qnareply.insertReply", rvo);
	}
	
	@Override
	// 댓글 상세보기
	public List<ReplyVO> getListReply(int bno) throws SQLException {
		//System.out.println("getListReply Dao");
		return sqlSessionTemplate.selectList("qnareply.getListReply",bno);
	}
	
	@Override
	// 댓글 삭제
	public void deleteReply(int rno) throws SQLException {
		sqlSessionTemplate.delete("qnareply.deleteReply",rno);
	}
	
	@Override
	// 댓글 수정
	public void updateReply(ReplyVO rvo) throws SQLException {
		sqlSessionTemplate.update("qnareply.updateReply",rvo);	
	}

	@Override
	//대댓글 입력
	public void updateRestep(int ref, int restep) throws SQLException {
		HashMap<String,Integer> map = new HashMap<String,Integer>();
		map.put("ref", ref);
		map.put("restep", restep);
		sqlSessionTemplate.insert("qnareply.updateRestep",map);
	}

	@Override
	public void insertReReply(ReplyVO rvo) throws SQLException {
		sqlSessionTemplate.insert("qnareply.insertReReply",rvo);
	}

	@Override
	public int selectRestep(int ref) throws SQLException {
		System.out.println(ref+" dao");
		//System.out.println(sqlSessionTemplate.selectOne("qnareply.selectRestep",ref)+" dao");
		return sqlSessionTemplate.selectOne("qnareply.selectRestep",ref);
	}

	@Override
	public void checkRadpot(int rno) throws SQLException {
		sqlSessionTemplate.selectOne("qnareply.checkRadpot",rno);
	}

	@Override
	public void pointPlus(String id) throws SQLException {
		sqlSessionTemplate.update("qnareply.pointPlus",id);
	}
}
